//package com.rephone.test;
//
//import java.util.concurrent.ForkJoinPool;
//import java.util.concurrent.ForkJoinTask;
//import java.util.stream.LongStream;
//
///**
// * @description:
// * @author:Ihope
// * @date: 2024-12-29 09:53
// * @version:
// */
//public class ForkJoinSumCalculator extends java.util.concurrent.RecursiveTask<Long> {
//  private final long[] numbers;
//  private final int start;
//  private final int end;
//  public static final long THRESHOLD = 1000;
//
//  public ForkJoinSumCalculator(long[] numbers) {
//    this(numbers, 0, numbers.length);
//  }
//
//  private ForkJoinSumCalculator(long[] numbers, int start, int end) {
//    this.numbers = numbers;
//    this.start = start;
//    this.end = end;
//  }
//
//  @Override
//  protected Long compute() {
//    int length = end - start;
//    if (length <= THRESHOLD) {
//      return computeSequentially();
//    }
//    ForkJoinSumCalculator leftTask = new ForkJoinSumCalculator(numbers, start, start + length / 2);
//    leftTask.fork();
//    ForkJoinSumCalculator rightTask = new ForkJoinSumCalculator(numbers, start + length / 2, end);
//    Long rightResult = rightTask.compute();
//    Long leftResult = leftTask.join();
//    return leftResult + rightResult;
//  }
//
//  private long computeSequentially() {
//    long sum = 0;
//    for (int i = start; i < end; i++) {
//      sum += numbers[i];
//    }
//    return sum;
//  }
//
//  public static void main(String[] args) {
//    long[] numbers = LongStream.rangeClosed(1, 1000000).toArray();
//    ForkJoinTask<Long> task = new ForkJoinSumCalculator(numbers);
//    Long invoke = new ForkJoinPool().invoke(task);
//    System.out.println(invoke);
//  }
//}
